package com.global.variable.common.web.utils;

import com.google.common.collect.Lists;

import java.util.List;

/**
 * company 重庆庆云石油工程技术有限责任公司
 * FileName SqlUtils
 * Package com.basic.management.logic.util
 * Description Sql工具
 * author Administrator
 * create 2018-09-13 上午 11:31
 * version V1.0
 */
public final class SqlUtils {

    private SqlUtils() {

    }

    public static SqlUtils getInstance() {
        return Holder.instance;
    }

    public List<List<String>> getSQLIn(List<String> ids, int count) {
        List<List<String>> idList = Lists.newArrayList();
        count = Math.min(count, 1000);
        int len = ids.size();
        int size = len % count;
        if (size == 0) {
            size = len / count;
        } else {
            size = (len / count) + 1;
        }
        for (int i = 0; i < size; i++) {
            int fromIndex = i * count;
            int toIndex = Math.min(fromIndex + count, len);
            idList.add(ids.subList(fromIndex, toIndex));
        }
        return idList;
    }

    public static class Holder {
        private static SqlUtils instance = new SqlUtils();
    }
}
